package com.kevin.swing.impl;

import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.text.DefaultStyledDocument;
import javax.swing.text.StyledDocument;

import lombok.Data;
import lombok.EqualsAndHashCode;

import com.kevin.MainFrame;
import com.kevin.swing.TextPaneKevin;

@EqualsAndHashCode(callSuper = false)
/**
 * 
 * 帮助
 * @ClassName HelpDialog
 * @author <a href="mailto:donggongai@126.com" target="_blank">kevin</a>
 * @date 2016年9月24日 上午10:45:04
 *
 */
public @Data class HelpDialog extends JDialog {
    private MainFrame owner;

    /**
	 * 
	 */
    private static final long serialVersionUID = 6792501234970299123L;

    private TextPaneKevin wordSetTA;
    private JScrollPane wordSetJsp;

    private JPanel btnPanel = new JPanel();
    private JButton clbtn = new JButton("取消");

    public HelpDialog(MainFrame owner) {
        super();
        this.owner = owner;
        StyledDocument styledDoc = new DefaultStyledDocument();
        wordSetTA = new TextPaneKevin(styledDoc);
        wordSetTA.setBorder(BorderFactory.createTitledBorder("使用说明"));

        wordSetTA.insertDoc("1、使用前请先到“系统”》“数据库设置”中设置");
        wordSetTA.insertHighLightDoc("数据库配置");
        wordSetTA.insertDoc("，设置好后“测试连接”确认可以连接后点击“保存”按钮；\n");
        wordSetTA.insertDoc("2、数据库设置好后，在主界面的输入框中输入表名点击“搜索”按钮进行");
        wordSetTA.insertHighLightDoc("搜索");
        wordSetTA.insertDoc("，或者不输入表名直接点击“搜索”按钮搜索该数据库的全部表；\n");
        wordSetTA.insertDoc("3、搜索出表后点击表名前的复选框勾选表，然后点击下一步；\n");
        wordSetTA.insertDoc("4、确认选中的表无误，点击下一步；\n");
        wordSetTA.insertDoc("5、在这一步中界面会显示所选表的所有字段及类型注释，其中");
        wordSetTA.insertHighLightDoc("导出字段名、导出字段类型、注释");
        wordSetTA.insertDoc("三列");
        wordSetTA.insertHighLightDoc("可修改");
        wordSetTA.insertDoc("，（注释修改完成后点击一下其他单元格，否则当前单元格的修改可能");
        wordSetTA.insertHighLightDoc("不起作用");
        wordSetTA.insertDoc("），点击“导出”按钮导出即可。\n\n");
        wordSetTA.insertHighLightDoc("注：\n");
        wordSetTA.insertDoc("1、其中");
        wordSetTA.insertHighLightDoc("第2步");
        wordSetTA.insertDoc("和");
        wordSetTA.insertHighLightDoc("第5步");
        wordSetTA.insertDoc("的搜索结果默认有");
        wordSetTA.insertHighLightDoc("缓存");
        wordSetTA.insertDoc("，如果想清除缓存点击“搜索表”或“重新载入”按钮。\n");
        wordSetTA.insertDoc("2、关于");
        wordSetTA.insertHighLightDoc("驼峰命名");
        wordSetTA.insertDoc("：\n");
        wordSetTA.insertDoc("第5步中导出字段修改过会默认缓存起来，下次遇到同样的字段会自动转换为之前修改过的名字，如果要清空请到");
        wordSetTA.insertHighLightDoc("“系统”>“常用词设置”");
        wordSetTA.insertDoc("（相等关系）中进行更改,如设置createtime=createTime，则遇到名称为createtime的字段导出时自动转换为createTime。");
        wordSetTA.insertDoc("一些常用的内嵌单词可以到");
        wordSetTA.insertHighLightDoc("“系统”>“分词设置”");
        wordSetTA.insertDoc("（包含关系）中设置，如设置了bh则companbh导出时自动转换为companyBh。");

        wordSetJsp = new JScrollPane(wordSetTA);
        wordSetJsp.setBorder(null);
        clbtn = new JButton("关闭");

        btnPanel = new JPanel();
        btnPanel.add(clbtn);

        setTitle("帮助");
        add(wordSetJsp, BorderLayout.CENTER);
        add(btnPanel, BorderLayout.SOUTH);
        setVisible(false);
        setSize(450, 400);
        setResizable(false);
        init();
    }

    private void init() {
        clbtn.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent arg0) {
                HelpDialog.this.setVisible(false);
            }
        });

    }

}
